﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SilverlightParser.Web.Backend
{
    public class RemotableMentorProxy
    {
        public List<Semantics.Silverlight.Category> GetSubCategories(int nodeid)
        {
            ArrayList categories = Remoter.GetRemoter().GetRemotableType().GetSubCategories(nodeid);
            return ToSilverCategories(categories);
        }
        List<Semantics.Silverlight.Category> ToSilverCategories(ArrayList categories)
        {

            List<Semantics.Silverlight.Category> silvercates = new List<Semantics.Silverlight.Category>();
            for (int i = 0; i < categories.Count; i++)
            {
                silvercates.Add(this.ToSilverCategory((Semantics.Base.Category)categories[i]));
            }
            return silvercates;
        }


        public Semantics.Silverlight.Category ToSilverCategory(Semantics.Base.Category cate)
        {
            Semantics.Silverlight.Category silvercate = new Semantics.Silverlight.Category();
            silvercate.NodeId = cate.Node.Id;
            if(cate.Parent!=null)
                silvercate.ParentId = cate.Parent.Id;
            silvercate.Value = cate.Node.Value;
            silvercate.Example = cate.Example;
            return silvercate;
        }
        public int CreateWord(string word, int categorynodeid)
        {
            int result = Remoter.GetRemoter().GetRemotableType().CreateNode(word, categorynodeid);
            return result;
        }
        public List<Semantics.Silverlight.Category> SearchCategories(string word)
        {
            ArrayList categories = Remoter.GetRemoter().GetRemotableType().SearchCategories(word);
            return ToSilverCategories(categories);
        }
        public List<Semantics.Silverlight.Category> GetCategroyHierarchy(int nodeid)
        {
            ArrayList categories = Remoter.GetRemoter().GetRemotableType().GetCategroyHierarchy(nodeid);
            return ToSilverCategories(categories);
        }
    }
}